package com.njtoyo.taxi.admin.rest.controller.business.driver;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.business.driver.system_message.DriverSystemMessageDetailPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.system_message.EditWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.driver.system_message.ListWrapper;
import com.njtoyo.taxi.admin.service.business.driver.SystemMessageService;
import com.taxi.entity.common.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@Api(tags = "司机系统消息")
@RequestMapping("/business/driver/system_message")
public class SystemMessageController {

    @Autowired
    private SystemMessageService systemMessageService;

    @GetMapping()
    @ApiOperation(value = "获取司机系统消息列表", notes = "权限: driver_system_message")
    @ApiOperationSupport(order = 1)
    @PermissionScope(names = {"driver_system_message"})
    RestResult getList(@Valid ListWrapper listWrapper) {
        return systemMessageService.getList(listWrapper);
    }

    @PutMapping()
    @ApiOperation(value = "编辑司机系统消息", notes = "权限: driver_system_message_edit")
    @ApiOperationSupport(order = 2)
    @PermissionScope(names = {"driver_system_message_edit"})
    RestResult edit(@Valid @RequestBody EditWrapper editWrapper) {
        return systemMessageService.edit(editWrapper);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除司机系统消息", notes = "权限：driver_system_message_edit")
    @ApiOperationSupport(order = 3)
    @PermissionScope(names = {"driver_system_message_edit"})
    RestResult delete(@PathVariable("id") Long id) {
        return systemMessageService.delete(id);
    }

    @DeleteMapping("/cache")
    @ApiOperation(value = "清除司机系统消息缓存", notes = "权限：driver_system_message_edit")
    @ApiOperationSupport(order = 4)
    @PermissionScope(names = {"driver_system_message_edit"})
    RestResult deleteCache() {
        return systemMessageService.deleteCache();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "获取司机系统消息详情", notes = "权限: driver_system_message")
    @PermissionScope(names = {"driver_system_message"})
    public RestResult<DriverSystemMessageDetailPresenter> getDetail(@PathVariable("id") Long id) {
        return systemMessageService.getDetail(id);
    }
}
